<template>
	<div class="zs-table-page-container">
		<div class="zs-card-sm zs-space-bottom zs-layout-flex-row zs-layout-justify-between">
			<div>
				<el-date-picker v-model="queryParams.yearMonth" type="month" class="zs-select-md zs-space-right-sm" placeholder="时间" value-format="YYYY-MM" @change="queryList" />
				<el-select v-model="queryParams.type" class="zs-select-md zs-space-right-sm" placeholder="楼栋经理" @change="queryList" clearable filterable>
					<el-option v-for="item in manageTypeList" :key="item.key" :label="item.label" :value="item.key" />
				</el-select>
				<el-button class="zs-btn-plain" @click="queryList"> 查询 </el-button>
			</div>
		</div>

		<!-- teble -->
		<div class="zs-card zs-table-page-content">
			<el-table class="zs-table-page-main" :data="tableData.data" v-loading="tableData.loading" stripe>
				<el-table-column type="index" label="序号" width="60" align="center" :index="index => index + 1 + (tableData.currentPage - 1) * curPageSize" />
				<el-table-column prop="jeezId" label="极致项目标识" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column v-if="queryParams.type == 2" prop="buildId" label="极致物业楼栋id" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column v-if="queryParams.type == 2" prop="buildName" label="极致物业楼栋名称" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="staffCode" label="员工工号" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="settleStaffCode" label="结算系统员工工号" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="staffName" label="员工姓名" align="center" :formatter="defaultTableData" />
				<el-table-column prop="mobile" label="手机号码" align="center" :formatter="defaultTableData" />
			</el-table>
			<div class="zs-space-top-sm zs-table-page-pagination">
				<el-pagination v-model:currentPage="tableData.currentPage" v-model:page-size="curPageSize" :page-sizes="curPageSizes" :small="true" :background="true" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="pageChange('size', $event)" @current-change="pageChange('page', $event)" />
			</div>
		</div>
	</div>
</template>

<script setup>
	import { getStaffPropertyListApi } from '@/api/residence.js';
	import { ref, reactive } from 'vue';
	import { useStore } from 'vuex';
	import { useRoute } from 'vue-router';
	import { defaultTableData } from '@/utils/publicUtils';

	const route = useRoute();
	const store = useStore();
	const curPageSizes = ref(store.state.uiPageSizes);
	const curPageSize = ref(store.state.uiPageSizeDefault);
	const manageTypeList = ref([
		{ key: 1, label: '项目经理' },
		{ key: 2, label: '栋号经理' },
	]);

	// 列表 filed
	const tableData = reactive({
		currentPage: 1,
		total: 0,
		loading: false,
		data: [],
	});

	//查询条件
	const queryParams = reactive({ projectCode: route.query.projectCode, pageNumber: 1, pageSize: curPageSize.value, type:2 });

	// 列表数据源
	const queryList = async () => {
		tableData.loading = true;
		let res = await getStaffPropertyListApi(queryParams);
		if (res.data.code !== 200) return;
		tableData.data = res.data.data.list || [];
		tableData.total = res.data.data.total || 0;
		tableData.loading = false;
	};

	// 分页
	const pageChange = (type, size) => {
		if (type == 'size') {
			queryParams.pageSize = size;
		} else {
			queryParams.pageNumber = size;
		}
		queryList();
	};

	queryList();
</script>
